<template>
  <div class="index_search">
    <div @click="goBack" class="go_back">
      <span class="iconfont icon-icon4"></span>
    </div>
    <div class="search_content">
      <div>
        <span>
          <select name="" id="indexSearch">
            <option value="">资讯百科</option>
            <option value="">视频海南</option>
          </select>
          <span class="iconfont icon-xiala"></span>
        </span>
      </div>
      <div>
        <input type="text" v-model="inputValue" @input="searchGo()" placeholder="请输入关键词">
      </div>
      <div class="chahao">
        <span @click="chaHao" v-if="searchOrCancel === true" class="iconfont icon-chahao"></span>
      </div>
    </div>
    <div class="go_del">
      <span v-if="searchOrCancel === false" @click="goBack">取消</span>
      <span v-else @click="searchResult()">搜索</span>
    </div>
  </div>
</template>

<script>
  import {saveSearch} from '../../assets/js/cache'  //引用本地存储js

  export default {
    props:{
      getHistoryTitle:{
        type:Function
      }
    },
    name: 'IndexSearchTop',
    data() {
      return {
        inputValue:'',
        searchOrCancel:false
      }
    },
    created() {

    },
    methods: {
      goBack() {
        this.$router.push({name: 'Index'});
      },
      //判断input有没有值 切换 取消 与搜索按钮
      searchGo(){
        if(this.inputValue !== ''){
          this.searchOrCancel = true
        } else {
          this.searchOrCancel = false
        }

      },
      //搜索按钮
      searchResult(){
        saveSearch(this.inputValue);
        this.getHistoryTitle();
      },
      //叉号
      chaHao(){
        this.inputValue = '';
        this.searchGo();
      }
    },
    beforeDestroy() {

    }

  }
</script>

<style scoped>
  #indexSearch {
    border: none;
    appearance: none;
    -moz-appearance: none;
    -webkit-appearance: none;
    background-color: #f8f8f8;
  }

  .index_search {
    height: 40px;
    background-color: #ffffff;
    padding: 0.5rem;
    display: flex;
    display: -webkit-flex; /* Safari */
    flex-direction: row;
    flex-wrap: nowrap;
    line-height: 40px;
    color: #333333;
  }

  .index_search .go_back {
    margin-right: 10px;
  }

  .index_search .search_content {
    background-color: #f8f8f8;
    border-radius: 0.5rem;
    /*width: 80%;*/
    display: flex;
    padding: 0 0.5rem;
  }

  .go_del {
    width: 3rem;
    text-align: center;
  }

  .index_search .search_content > div:nth-child(1) {
    width: 6rem;
  }

  .index_search .search_content > div:nth-child(2) {
    /*width: 45%;*/
    /*flex: 3;*/
  }

  .index_search .search_content > div:nth-child(3) {

  }

  .index_search .search_content input {
    width: 100%;
    border: none;
    outline: none;
    /*border-left: 1px solid #dcdcdc;*/
    background-color: #f8f8f8;
  }
.index_search .search_content .chahao{
  color: #999;
}
</style>
